home *** CD-ROM | disk | FTP | other *** search
- Path: news-m01.ny.us.ibm.net!usenet
- From: rpsilva@ibm.net
- Newsgroups: comp.lang.c++
- Subject: Problems with Borland C++ 4.52 accessing global data within a DLL
- Date: 23 Mar 1996 16:02:14 GMT
- Message-ID: <4j17a6$2518@news-s01.ny.us.ibm.net>
- Reply-To: rpsilva@ibm.net
- NNTP-Posting-Host: slip166-72-221-84.tx.us.ibm.net
- X-Newsreader: IBM NewsReader/2 v1.2
-
- Hi everybody,
-
- I am porting some code from OS/2 to NT using Borland 4.52 compiler
- ( under OS/2 I am using Borland C++ 2.0 ).
-
- I am facing a problem accessing static data members defined inside of a
- DLL. The set of modules used to link the DLL itself, do not have any problem
- accessing them. The problem raises when an application uses the DLL and
- accesses a static pointer( peharps with any global data ). I have written
- a tiny example, and I've tested it with VC ++ 2.0 and it worked.
-
-
- Sample: ( Using Borland code ). It may have sintaxe errors
-
- // DLL code
-
- // MODULE mydll.h
- #ifdef __DLL__
- #define C_EXPORT _export
- #else
- #define C_EXPORT
- #endif
-
- class C_EXPORT MyClass
- {
- public:
- MyClass();
- ~MyClass();
-
- void method1( int x );
- static MyClass *ptr;
-
- private:
- int y;
- };
- // End of mydll.h
- /////////////////////////////////////////////////////////
-
- // MODULE mydll.cpp
- MyClass *MyClass::ptr = 0;
-
- MyClass::MyClass()
- {
- if( !MyClass::ptr )
- MyClass::ptr = this;
- printf( "Ctor - MyClass: MyClass::ptr= %p\n", MyClass::ptr );
- y = 0;
- }
-
- MyClass::~MyClass()
- {
- printf( "Dtor - MyClass\n" );
- }
-
- void MyClass::method1( int x )
- {
- y = x;
- printf( "method1: %d\n", x );
- }
- // End of mydll.cpp
- /////////////////////////////////////////////////////////
-
- // MODULE myexe.cpp
- #include <stdio.h>
- #include "mydll.h"
-
- void main( void )
- {
- MyClass m;
-
- m.method1( 3 );
-
- // Generates an access violation here
- MyClass::ptr->method1( 4 );
- }
- // End of myexe.cpp
- /////////////////////////////////////////////////////////
-
- Question:
-
- 1. Is there a problem with the Borland C++ 4.52 accessing global data
- within a DLL under NT ? ( the same code works under OS/2 environment )
-
- 2. Am I doing something wrong ?
-
- Thanks for your help.
- Rosimildo.
-